# vim:ts=4:sw=4:noet:
""" Main menubar """

import wx
from c.ui.wxw.ids import ids, shortcuts

class MainMenu(wx.MenuBar):
	def __init__(self, parent):
		wx.MenuBar.__init__(self)

		# file menu
		fileMenu = wx.Menu()
		self.addItem(fileMenu, ids.FILE_NEW_PROJECT, "New Project")
		fileMenu.AppendSeparator()
		self.addItem(fileMenu, ids.FILE_OPEN, "Open ...")
		self.examplesMenu = wx.Menu()
		self.addSubMenu(fileMenu, ids.FILE_EXAMPLES, self.examplesMenu, "Open Example")
		self.addItem(fileMenu, ids.FILE_SAVE, "Save", False)
		self.addItem(fileMenu, ids.FILE_SAVE_AS, "Save As ...", False)
		fileMenu.AppendSeparator()
		self.addItem(fileMenu, ids.FILE_EXIT, "Exit")
		# edit menu
		editMenu = wx.Menu()
		self.addItem(editMenu, ids.EDIT_UNDO, "Undo", False)
		self.addItem(editMenu, ids.EDIT_REDO, "Redo", False)
		editMenu.AppendSeparator()
		self.addItem(editMenu, ids.EDIT_CUT, "Cut", False)
		self.addItem(editMenu, ids.EDIT_COPY, "Copy", False)
		self.addItem(editMenu, ids.EDIT_PASTE, "Paste", False)
		# view menu
		viewMenu = wx.Menu()
		self.addItem(viewMenu, ids.VIEW_CONSOLE, "Toggle Console")
		self.addItem(viewMenu, ids.VIEW_DOCUMENTATION, "Show Docs")
		viewMenu.AppendSeparator()
		self.addItem(viewMenu, ids.VIEW_JUMPTO, "Jump To ...", False)
		# project menu
		projectMenu = wx.Menu()
		self.addItem(projectMenu, ids.PROJECT_COMPILE, "Check")
		self.addItem(projectMenu, ids.PROJECT_RUN, "Run")
		self.addItem(projectMenu, ids.PROJECT_STOP, "Stop")
		projectMenu.AppendSeparator()
		self.addItem(projectMenu, ids.PROJECT_NEW_CLASS, "New Class")
		self.addItem(projectMenu, ids.PROJECT_NEW_METHOD, "New Method")
		projectMenu.AppendSeparator()
		self.addItem(projectMenu, ids.PROJECT_IMPORT_CLASS, "Import Class ...")
		projectMenu.AppendSeparator()
		self.addCheckItem(projectMenu, ids.PROJECT_EDIT_LIBRARY, "Editable Library")
		self.addCheckItem(projectMenu, ids.PROJECT_AUTO_SWITCH, "Switch to Robot on Run")
		# dev menu
		devMenu = wx.Menu()
		self.addItem(devMenu, ids.DEV_CRASH, "Crash")
		self.addItem(devMenu, ids.VIEW_GET_INFO, "Get Info")
		self.addItem(devMenu, ids.PROJECT_EXPORT_ALL, "Export All Classes")
		# help menu
		helpMenu = wx.Menu()
		helpMenu.Append(ids.HELP_REFERENCE, "Reference Manual"+shortcuts.HELP_REFERENCE)
		helpMenu.Append(ids.HELP_TUTORIAL, "Tutorial"+shortcuts.HELP_TUTORIAL)
		helpMenu.AppendSeparator()
		helpMenu.Append(ids.HELP_ABOUT, "About"+shortcuts.HELP_ABOUT)
		
		self.Append(fileMenu, "&File")
		self.Append(editMenu, "&Edit")
		self.Append(viewMenu, "&View")
		self.Append(projectMenu, "&Project")
		#self.Append(devMenu, "&Dev")
		self.Append(helpMenu, "&Help")
		self.examples = {}

	def addItem(self, menu, id, text, enabled=True):
		sc = ids.shash[id]
		menu.Append(id, text+sc)
		menu.Enable(id, enabled)

	def addSubMenu(self, menu, id, submenu, text, enabled=True):
		sc = ids.shash[id]
		menu.AppendMenu(id, text+sc, submenu)
		menu.Enable(id, enabled)

	def addCheckItem(self, menu, id, text, enabled=True):
		sc = ids.shash[id]
		menu.AppendCheckItem(id, text+sc)
		menu.Enable(id, enabled)

	def addExample(self, name, filename):
		id = wx.NewId()
		self.examples[id] = filename
		self.examplesMenu.Append(id, name)
